package com.eCommercecorecontract.svco;

import java.util.Map;



public class SVCOFinder {
	
	public SVCOFinder(){
		
	}
	/**
	    * Dictionary where we store the SVCO Components of a project.
	    * Any SVCO Component will be store with a key. 
	    * 
	    */
	   private Map<String,IServiceComposed>map;
		   
		/**
		 * Assign a map to the SVCOFinder
		 * throws an exception if the map has already been set
		 * @param value
		 * @throws Exception
		 */
		public void setMap(Map<String,IServiceComposed> value)throws Exception
		{
			if (map != null)
	       {
	           String msg = "The dictionary of SVCO components are already load. You can not do it again...";
	           Exception ex = new Exception(msg);
	           throw ex;
	       }

	       map = value;
		}
		
		
		/**
		 * Get service through its key
		 */
		public IServiceComposed get(String key) throws Exception
		{
			try
	       {
	           // To do if the caller is not an ISVCO throws an exception

	           IServiceComposed svco = (IServiceComposed)map.get(key);
	           if (svco == null)
	           	throw new Exception("The key -" + key + "- are not defined in SVCO Finder");
	           return svco;
	       }
	       catch (Exception ex)
	       {
	           String exMsg = ex.getMessage();
	           if (map == null)
	               exMsg = "The Dictionry of SVCO Component are empty";

	           String msg = "Error while getting SVCO component : " + key + ". DETAILS:" + exMsg;
	           throw new Exception(msg);
	       }	
		}
}
